package com.snow.service.log.impl;

import com.snow.dao.LogDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.snow.service.log.LogService;
import com.snow.pojo.model.LogDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @author: snow
 * @Date: 2020-01-08
 **/

@Service
public class LogServiceImpl  implements LogService {
    @Autowired
    private LogDao logDao;


    @Override
    public void addLog(String action, String data, String ip, Integer authorId) {
        LogDomain logDomain = new LogDomain();
        logDomain.setAction(action);
        logDomain.setAuthorId(authorId);
        logDomain.setIp(ip);
        logDomain.setData(data);

        logDao.addLog(logDomain);

    }

    @Override
    public void deleteLogById(Integer id) {
        if(id == null){
            throw new RuntimeException("请求删除操作的日志id为Null");
        }
        logDao.deleteLogById(id);
    }

    @Override
    public PageInfo<LogDomain> getLogs(int pageNum, int size) {
        PageHelper.startPage(pageNum,size);
        List<LogDomain> logs = logDao.getLogs();
        PageInfo<LogDomain> logDomainPageInfo = new PageInfo<>(logs);
        return logDomainPageInfo;
    }
}
